package loan.calc.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import loan.calc.datasource.UseDataSource;
import loan.calc.dto.DictDTO;
import loan.calc.service.base.DictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("dict")
@Tag(name = "dict", description = "数据字典相关接口")
public class DictController {

    private final DictService dictService;

    @GetMapping("refreshDbSystemDict")
    @Operation(summary = "刷新数据库系统类型的数据字典")
    @Transactional(rollbackFor = Exception.class)
    public void refreshDbSystemDict() throws ClassNotFoundException {
        dictService.refreshDbSystemDict();
        dictService.loadAllDict();
    }

    @GetMapping("loadDict")
    @Operation(summary = "加载码表")
    public List<DictDTO> loadDict() {
        return dictService.loadAllDict();
    }
}
